package com.swlz.servlet.user;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.swlz.R;
import com.swlz.vo.LoginUser;
import com.swlz.entity.MallAddress;
import com.swlz.exception.CodeException;
import com.swlz.service.MallAddressService;
import com.swlz.service.impl.MallAddressServiceImpl;
import com.swlz.servlet.HttpServletSupport;

/**
 * <pre>
 * - JSON控制器
 * - 商城用户收货地址
 * ClassName : com.swlz.servlet.demo.MallAddressServlet
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-07-04 06:11:27
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
@SuppressWarnings("serial")
@WebServlet("/user/mall-address.let")
public class MallAddressServlet extends HttpServletSupport {
	
	private MallAddressService mallAddressService = new MallAddressServiceImpl();

	public Object add(LoginUser user,MallAddress mallAddress)throws Exception {
		mallAddress.setUserId(user.getUserId());
		if(mallAddress.getAddressDefault()==null){
			mallAddress.setAddressDefault(false);
		}
		mallAddressService.add(mallAddress);
		return R.ok();
	}
	
	public Object update(LoginUser user,MallAddress mallAddress)throws Exception {
		mallAddress.setUserId(user.getUserId());
		if(mallAddress.getAddressDefault()==null){
			mallAddress.setAddressDefault(false);
		}
		mallAddressService.update(mallAddress);
		return R.ok();
	}
	
	public Object delete(LoginUser user,MallAddress mallAddress)throws Exception {
		mallAddressService.delete(mallAddress.getAddressId());
		return R.ok();
	}
}